﻿/*
 * 报告查询UI。2009-8-4
 * 根据各种条件查询报告。
 * 
 * 
 * */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using EQT.Model;
public partial class ReportQuery : System.Web.UI.Page
{
    private DaSysCoding dasc = new DaSysCoding(DaCommon.DefaultDb);
    private DaContract dacontract = new DaContract(DaCommon.DefaultDb);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //初次对页面进行数据绑定
            TextBoxBegin.Text = String.Format("{0}-01-01", DateTime.Now.Year);
            TextBoxEnd.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");

            //绑定合同状态下拉列表
            Utility.BindListCtl2Dic(DropDownListStatus, ContractStatusCollection.CommonGrpStatus);
            InitDefaultFitler();
            LoadContractList();
        }

    }

    private void InitDefaultFitler()
    {
        DateTime default_begin_day = new DateTime(DateTime.Today.Year, 1, 1);
        TextBoxBegin.Text = default_begin_day.ToString(SiteConfig.DateFormat);
        TextBoxEnd.Text = DateTime.Now.AddDays(1).ToString(SiteConfig.DateFormat);
        DropDownListStatus.SelectedIndex = DropDownListStatus.Items.IndexOf(DropDownListStatus.Items.FindByValue(ContractStatus.ALL.ToString()));
        TextBoxReportId.Text = String.Empty;
        TextBoxCorpName.Text = String.Empty;

        AspNetPager1.PageSize = SiteConfig.PageSize;

    }


    /// <summary>
    /// 加载合同列表
    /// </summary>
    private void LoadContractList()
    {
        #region 构建过滤字符串
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //时间范围是必须的
        sb.Append(DaContract.SELECT_CONTRACTS_FILEDS);
        sb.Append(Utility.GenerateQueryFilter2DateTime("CREATE_TIME", TextBoxBegin.Text, TextBoxEnd.Text));
        string filter = Utility.GenerateQueryFilterString("Report_ID", TextBoxReportId.Text, 2);
        if (filter != null) sb.AppendFormat(" AND {0} ", filter);
        filter = Utility.GenerateQueryFilterString("Corp_Name", TextBoxCorpName.Text, 2);
        if (filter != null) sb.AppendFormat(" AND {0} ", filter);

        sb.AppendFormat(" AND {0}",Utility.GenerateQueryFilterIntMaskAnd("Report_Status","&", Int32.Parse(DropDownListStatus.SelectedValue)));
        string sql = sb.ToString();
        if(Utility.GlobalLog.IsDebugEnabled) Utility.GlobalLog.Debug(sql);
        int totalCount = 0;
        #endregion

        DataSet ds = DaCommon.GetPaginationData(sql,
            SiteConfig.PageSize, AspNetPager1.CurrentPageIndex - 1, "Create_Time DESC", out totalCount);
        
        AspNetPager1.RecordCount = totalCount;
        GridViewContracts.DataSource = ds;
        GridViewContracts.DataBind();

    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        LoadContractList();
    }
    protected void btnFilterQuery_Click(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 0;       
        LoadContractList();
    }
    protected void btnQueryAll_Click(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 0;     
        InitDefaultFitler();
        LoadContractList();
    }
}
